package com.service.lyxmservice.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.service.lyxmserviceapi.model.ArticleModel;
import com.service.lyxmserviceapi.model.Author;
import com.service.lyxmserviceapi.model.Module;
import com.service.lyxmserviceapi.model.Mp;


@Mapper
public interface ArticleDetailDao {
		
	@Select("SELECT t.id,t.title,t.context,t.cover_file_src as coverFileSrc,DATE_FORMAT(t.create_time,'%Y-%m-%d') AS createTimeStr,t.author_id AS authorId,read_num AS readNum, t.cover_file_src_s as coverFileSrcS,t.mp_id AS mpId,t.module_id AS moduleId,t.cover_file_src as coverFileSrc , t.target as target FROM t_article t where t.id = #{id}")                   
	@Results({
		@Result(property="author",column="authorId",one=@One(select="com.service.lyxmservice.dao.ArticleDetailDao.findAuthorById")),
		@Result(property="mp",column="mpId",one=@One(select="com.service.lyxmservice.dao.ArticleDetailDao.findMpById")),
		@Result(property="module",column="moduleId",one=@One(select="com.service.lyxmservice.dao.ArticleDetailDao.findModuleById")),
		})
	public ArticleModel getArticleById(@Param("id")String id);
	
	@Select("select * from t_author where id=#{authorId}")
	public Author findAuthorById(int authorId);
	
	@Select("select * from t_mp3 where id=#{id}")
	public Mp findMpById(int id);
	
	@Select("select * from t_module where id=#{id}")
	public Module findModuleById(int id);
	
	
	@Select("SELECT t.id,t.title,DATE_FORMAT(t.create_time,'%Y-%m-%d') AS createTimeStr,t.description as description,t.cover_file_src as coverFileSrc, t.cover_file_src_s as coverFileSrcS FROM t_article t where t.id != #{articleId} and t.author_id = #{authorId} GROUP BY create_time DESC")
	public List<ArticleModel> getArticleModelListWithOutOneId(@Param("articleId")String articleId,@Param("authorId")String authorId);

	
	@Select("SELECT t.id,t.title,DATE_FORMAT(t.create_time,'%Y-%m-%d') AS createTimeStr,t.description as description,t.cover_file_src as coverFileSrc, t.cover_file_src_s as coverFileSrcS FROM t_article t  GROUP BY create_time DESC LIMIT 3")
	public List<ArticleModel> getArticleModelListIndex();



}
